package edu.hwadee.BEIS.entity;
// default package

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.format.annotation.DateTimeFormat;

/**
 * Announcement entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "announcement", catalog = "beis")

public class Announcement implements java.io.Serializable {

	// Fields

	private Integer announcementId;
	private CityUser cityUser;
	private String announcementName;
	private String announcementInfor;
	private String announcementType;
	private String announcementFile;
	private Set<LeaderUser> leaderUsers = new HashSet<LeaderUser>(0);
	private Set<SchoolUser> schoolUsers = new HashSet<SchoolUser>(0);
	private Set<CountyUser> countyUsers = new HashSet<CountyUser>(0);

	@JSONField(format = "yyyy-MM-dd HH:mm:ss")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date publishTime;

	// Constructors

	/** default constructor */
	public Announcement() {
	}

	/** minimal constructor */
	public Announcement(CityUser cityUser, String announcementName, String announcementInfor, String announcementType) {
		this.cityUser = cityUser;
		this.announcementName = announcementName;
		this.announcementInfor = announcementInfor;
		this.announcementType = announcementType;
	}

	/** full constructor */
	public Announcement(CityUser cityUser, String announcementName, String announcementInfor, String announcementType,
			Set<LeaderUser> leaderUsers, Set<SchoolUser> schoolUsers, Set<CountyUser> countyUsers) {
		this.cityUser = cityUser;
		this.announcementName = announcementName;
		this.announcementInfor = announcementInfor;
		this.announcementType = announcementType;
		this.leaderUsers = leaderUsers;
		this.schoolUsers = schoolUsers;
		this.countyUsers = countyUsers;
	}

	// Property accessors
	@GenericGenerator(name = "generator", strategy = "increment")
	@Id
	@GeneratedValue(generator = "generator")

	@Column(name = "announcement_id", unique = true, nullable = false)

	public Integer getAnnouncementId() {
		return this.announcementId;
	}

	public void setAnnouncementId(Integer announcementId) {
		this.announcementId = announcementId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "cityuser_id", nullable = false)

	public CityUser getCityUser() {
		return this.cityUser;
	}

	public void setCityUser(CityUser cityUser) {
		this.cityUser = cityUser;
	}

	@Column(name = "announcement_name", nullable = false, length = 20)

	public String getAnnouncementName() {
		return this.announcementName;
	}

	public void setAnnouncementName(String announcementName) {
		this.announcementName = announcementName;
	}

	@Column(name = "announcement_infor", nullable = false, length = 100)

	public String getAnnouncementInfor() {
		return this.announcementInfor;
	}

	public void setAnnouncementInfor(String announcementInfor) {
		this.announcementInfor = announcementInfor;
	}

	@Column(name = "announcement_type", nullable = false, length = 10)

	public String getAnnouncementType() {
		return this.announcementType;
	}

	public void setAnnouncementType(String announcementType) {
		this.announcementType = announcementType;
	}

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "leader_anouncement", joinColumns = { @JoinColumn(name = "announcement_id") }, inverseJoinColumns = {
			@JoinColumn(name = "leaderuser_id") })
	public Set<LeaderUser> getLeaderUsers() {
		return this.leaderUsers;
	}

	public void setLeaderUsers(Set<LeaderUser> leaderUsers) {
		this.leaderUsers = leaderUsers;
	}

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "school_anouncement", joinColumns = { @JoinColumn(name = "announcement_id") }, inverseJoinColumns = {
			@JoinColumn(name = "schooluser_id") })
	public Set<SchoolUser> getSchoolUsers() {
		return this.schoolUsers;
	}

	public void setSchoolUsers(Set<SchoolUser> schoolUsers) {
		this.schoolUsers = schoolUsers;
	}

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "county_anouncement", joinColumns = { @JoinColumn(name = "announcement_id") }, inverseJoinColumns = {
			@JoinColumn(name = "countyuser_id") })
	public Set<CountyUser> getCountyUsers() {
		return this.countyUsers;
	}

	public void setCountyUsers(Set<CountyUser> countyUsers) {
		this.countyUsers = countyUsers;
	}

	@Column(name = "announcement_file", nullable = false, length = 255)
	public String getAnnouncementFile() {
		return announcementFile;
	}

	public void setAnnouncementFile(String announcementFile) {
		this.announcementFile = announcementFile;
	}

	@Column(name = "publish_time", nullable = false)
	public Date getPublishTime() {
		return publishTime;
	}

	public void setPublishTime(Date publishTime) {
		this.publishTime = publishTime;
	}

	@Override
	public String toString() {
		return JSON.toJSONString(this);
	}

}